import { defineConfig } from "vite"
import path from "path"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
import compression from "vite-plugin-compression"

function isProd(str) {
	return str === "production"
}

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
	console.log("env==>", mode)

	return {
		plugins: [vue(), vueJsx(), compression()],
		resolve: {
			alias: [
				{
					find: "@",
					replacement: path.resolve(__dirname, "./src")
				}
			],
			extensions: [".js", ".jsx", ".json", ".ts", ".tsx", ".vue"]
		},
		server: {
			port: 7900,
			host: "0.0.0.0",
			hmr: {
				overlay: true
			}
		},
		css: {
			preprocessorOptions: {
				scss: {
					charset: false
				}
			}
		},
		esbuild: {
			drop: isProd(mode) ? ["console", "debugger"] : []
		},
		build: {
			minify: "esbuild",
			sourcemap: !isProd(mode),
			rollupOptions: {
				output: {
					chunkFileNames: "static/js/[name]-[hash].js",
					entryFileNames: "static/js/[name]-[hash].js",
					assetFileNames: "static/[ext]/[name]-[hash].[ext]"
				}
			}
		}
	}
})
